using Godot;
using System;
using System.Security.Cryptography;

public partial class NGame : Node2D
{
	Resource mAttackCursor;
	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
		mAttackCursor = CHelp.loadRes<Resource>("res://res/ui/mouse_attack.png");
	}

	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _Process(double delta)
	{
	}

	public override void _UnhandledInput(InputEvent @event)
	{
		NCharacter targetCha = CHelp.getChaWithPosition(this, GetGlobalMousePosition());
		if (targetCha != null && targetCha.mData.mChaType == CHA_TYPE.ENEMY)
		{
			CHelp.setCustomMouse(mAttackCursor);
		}
		else
		{
			CHelp.setCustomMouse(null);
		}

		if (@event is InputEventMouseButton mb)
		{
			if (mb.Pressed && mb.ButtonIndex == MouseButton.Right)
			{
				//从Friend组中取出角色
				NCharacter cha = CHelp.getTeamCha(this);
				if (targetCha != null && CHelp.canBattle(targetCha, cha))
				{
					//cha.mData.mSkillTarget.mID = SKILL_ID.SKILL_PYHSICS;
					cha.mData.mSkillTarget.mID = cha.mData.mDefauldID;

					cha.mData.mSkillTarget.mTargetPath = targetCha.GetPath().ToString();
					cha.mData.mState = new CPreSkillState();
				}
			}
			if (mb.ButtonIndex == MouseButton.WheelUp)
			{
				NCamera2D camera = CHelp.getNodeInGroup<NCamera2D>(this, nameof(NCamera2D));
				camera.Zoom += new Vector2(0.2f, 0.2f);
				if (camera.Zoom.X > 2)
				{
					camera.Zoom = new Vector2(2, 2);
				}
			}
			if (mb.ButtonIndex == MouseButton.WheelDown)
			{
				NCamera2D camera = CHelp.getNodeInGroup<NCamera2D>(this, nameof(NCamera2D));
				camera.Zoom -= new Vector2(0.2f, 0.2f);
				if (camera.Zoom.X < 1)
				{
					camera.Zoom = Vector2.One;
				}
			}
		}
	}
}
